<?php

/**
 * 管理后台
 * 
 * @author ShuangYa
 * @package Blog
 * @category Controller
 * @link http://www.sylingd.com/
 * @copyright Copyright (c) 2015 ShuangYa
 * @license http://lab.sylingd.com/go.php?name=blog&type=license
 */

namespace blog\controller;

use \sy\base\Controller;
use \sy\base\i18n;
use \sy\lib\YHtml;
use \sy\lib\db\YMysql;
use \sy\lib\YSecurity;
use \sy\lib\YCookie;
use \sy\tool\YFtp;
use \blog\libs\option;
use \blog\libs\BArticle;
use \blog\libs\BMeta;
use \blog\libs\BLink;

class Page extends Admin {
	protected $password;
	/**
	 * Home
	 */
	public function actionHome() {
		$this->checkLogin();
		Sy::setMimeType('html');
		Sy::view('admin/home');
	}
	/**
	 * 登录
	 */
	public function actionLogin() {
		Sy::setMimeType('html');
		if (isset($_POST['password'])) {
			if (YSecurity::password($_POST['password']) === $this->password) {
				YCookie::set(['name' => 'auth', 'value' => md5($this->password), 'httponly' => TRUE]);
				echo 1;
			} else {
				echo 0;
			}
		} else {
			if (!empty($_SERVER['HTTP_REFERER'])) {
				$redirect = $_SERVER['HTTP_REFERER'];
			} else {
				$redirect = Sy::createUrl('admin/home');
			}
			$redirect = addslashes($redirect);
			Sy::view('admin/login', ['redirect' => $redirect]);
		}
	}
	/**
	 * 退出
	 */
	public function actionLoginout() {
		YCookie::set(['name' => 'auth', 'value' => 'v', 'expire' => -1, 'httponly' => TRUE]);
		header('Location: ' . Sy::createUrl('admin/login'));
	}
}
